﻿using Iservices;
using System;
using System.Collections.Generic;
using System.Data;
using System.Threading.Tasks;
using Model;
using EFEntity;
using System.Linq;
using Microsoft.Data.SqlClient;
using AutoMapper;
using Microsoft.EntityFrameworkCore;

namespace Services
{
    /// <summary>
    ///  薪酬标准单详细信息   
    /// </summary>
    public class salary_standard_detailsServices:Isalary_standard_detailsServices
    {
        private readonly MyDbContext myDbContext;
        private readonly IMapper mapper;

        public salary_standard_detailsServices(MyDbContext myDbContext,IMapper mapper)
        {
            this.myDbContext = myDbContext;
            this.mapper = mapper;
        }
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public async Task<int> Add(salary_standard_details s)
        {
            Esalary_standard_details ss = mapper.Map<Esalary_standard_details>(s);
            myDbContext.salary_standard_details.Add(ss);
            int result = await myDbContext.SaveChangesAsync();
            return result;
        }
        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<int> Del(int id)
        {
            Esalary_standard_details list = myDbContext.salary_standard_details.Find(id);
            myDbContext.salary_standard_details.Remove(list);
            int re = await myDbContext.SaveChangesAsync();
            return re;
        }
        /// <summary>
        /// 查询全部
        /// </summary>
        /// <returns></returns>
        public async Task<List<salary_standard_details>> Select()
        {
            List<Esalary_standard_details> list = new List<Esalary_standard_details>();
            await Task.Run(() => {
                list = myDbContext.salary_standard_details.ToList();
            }); 
            List<salary_standard_details> list2 = mapper.Map<List<salary_standard_details>>(list);
            return list2;
        }
    }
}
